
% data source http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/fg/

clc;
%close all;
clear all;

Image = '35070'; fgdata = '105'; % '107'
%Image = '35058'; fgdata = '101'; % '109'
%Image = '35010'; fgdata = '107'; % '105'; % 
%Image = '2092'; fgdata = '104'; % '103'

Dir = 'I:/Heekko/VLab/Natural Images/BSDS300';
[seg, vals] = readSeg1(sprintf('%s/human/color/1105/%s.seg',Dir,Image));
bmap = seg2bmap(seg);
[cmap,cid2sid] = seg2cmap(seg,bmap);
FG = readbin(sprintf('%s/fgdata/color/1105/%s-%s.fg',Dir,Image,fgdata));

% natural image
figure;
I = imread(sprintf('%s/AllImages/%s.jpg',Dir,Image));
imagesc(I)

% contour by subjects 
figure;
imagesc(FG{1})

% image + contour by subjects
figure;
I = imread(sprintf('%s/AllImages/%s.jpg',Dir,Image));
imagesc(I)
hold on;
[a, b] = size(vals);
for ii = 1:b
    plot(vals(3:4,ii),vals(2,ii),'LineWidth', 50,'Color',[0.9 0.9 0.9]);
end

% labelling by subjects 
figure;
imagesc(cmap); colorbar;

FG{2}'


%% origoanl code
% To load a figure-ground labeling into MATLAB one may proceed with:
%     seg = readSeg('/home/eecs/fowlkes/BSDS300/human/color/1103/181091.seg');
%     bmap = seg2bmap(seg);
%     [cmap,cid2sid] = seg2cmap(seg,bmap);
%     FG = readbin('/home/eecs/fowlkes/fgdata/color/1103/181091-104.fg');
% This example loads image #181091 which has been segmented by subject #1103
% and each contour subsequently labeled by figure-ground subject #104. 
% FG{1} gives the figure/ground labeling encoded with two-pixel wide contours. 
% A alternate representation is contained in FG{2} which gives the label for each contour, 
% the support of the ith contour is given by (cmap==i) and the pair of
% abutting segments by cid2sid.